#include <iostream>
using namespace std;

const int maxn = 1e5+5;
string s;
int ans = 0,lp[maxn] = {0},rt[maxn] = {0};

signed main()
{
    cin>>s;
    int len = s.size();
    s = "0"+s;
    for(int i=1;i<=len;i++){
        if(s[i]=='P')    lp[i] = lp[i-1]+1;
        else    lp[i] = lp[i-1];
    }
    for(int i=len;i>=1;i--){
        if(s[i]=='T')    rt[i] = rt[i+1]+1;
        else    rt[i] = rt[i+1];
    }
    for(int i=2;i<=len-1;i++){
        if(s[i]=='A')    ans = (ans+lp[i-1]*rt[i+1])%1000000007;
    }
    cout<<ans<<"\n";
    return 0;
}
